#! /bin/bash

np=$1;
npstride=$2;
if  [[ $npstride != 1 ]]
then
    corenum[0]=1
    for i in `seq  $npstride $npstride $np`
    do
        corenum[$(($i/$npstride))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
else
    for i in `seq  1 $np`
    do
        corenum[$(($i-1))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
fi

for exe in 1d-jacobi-apop-blocking
do
    rm result/$exe-256.txt
    rm result/$exe-512.txt
    rm result/$exe-1024.txt
    for i in "${corenum[@]}";
    do
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 2000000 10000 256 64 >> result/$exe-256.txt 
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 2000000 10000 512 128 >> result/$exe-512.txt 
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 2000000 10000 1024 128 >> result/$exe-1024.txt 
        echo  $i >> result/1d-jacobi-apop-blocking.cpulist
    done
    done



cat result/1d-jacobi-apop-blocking-256.txt|awk -F "= " '{print $NF}'|paste result/1d-jacobi-apop-blocking.cpulist - - - >  result/1d-jacobi-apop-blocking.data.txt
cat result/1d-jacobi-apop-blocking-512.txt|awk -F "= " '{print $NF}'|paste  result/1d-jacobi-apop-blocking.data.txt - - - | awk '{printf("%d\t%f\t%f\t%f\n",$1,($2>$5)?$2:$5,($3>$6)?$3:$6,($4>$7)?$4:$7) }'> result/1d-jacobi-apop-blocking.data2.txt
cat result/1d-jacobi-apop-blocking-1024.txt|awk -F "= " '{print $NF}'|paste  result/1d-jacobi-apop-blocking.data2.txt - - - | awk '{printf("%d\t%f\t%f\t%f\n",$1,($2>$5)?$2:$5,($3>$6)?$3:$6,($4>$7)?$4:$7) }'> result/1d-jacobi-apop-blocking.data3.txt
echo -e "np\tscalar\tauto\tour" > result/1d-jacobi-apop-blocking.data.txt
cat result/1d-jacobi-apop-blocking.data3.txt >> result/1d-jacobi-apop-blocking.data.txt
rm  result/1d-jacobi-apop-blocking.cpulist
rm result/1d-jacobi-apop-blocking.data2.txt
rm result/1d-jacobi-apop-blocking.data3.txt
